require(['init'], function () {
var id = location.search.urlToObj().id;
var name = location.search.urlToObj().name;

console.log(id)

function getcommom(){
  $.ajax({
      url: '/api/marketing/contacts/'+id,
      type: 'get',
      success: function (data) { ///api/marketing/contacts/{id}
      //console.log(data)
       getcommom_record(data)

     },
     error:function(data){
     alert('cuole')
     }
  })
}

  function  getcommom_record(data){
    $('#commom_name').html('学生姓名：'+name)
   var $tbody=$('.tbody').html('');
   $.each(data.data,function(index,item){
    var $tr=$('<tr></tr>').appendTo($tbody);
    $tr.append('<td>'+(index+1)+'</td>');
    $tr.append('<td>'+item.content+'</td>');
    $tr.append('<td>'+item.created_at+'</td>');
    var $td=$('<td></td>').appendTo($tr);
    // var $edit=$('<a href="" class="btn btn-primary btn-sm btn-inverse ml5">编辑</a>').appendTo($td);
    var $delete=$('<a class="btn btn-danger btn-sm btn-inverse">删除</a>').appendTo($td);
    $delete.on('click',function(){
      alert("1")
      var popUpBox=new PopUpBox({
        type:'dom',
        style:'default contentScroll',
        submitBtnType:'confirm',
        titleText:'系统消息',
        drag:true,
        show:true,
        content:'<div style="margin-top:10px;margin-left:15px;">确认删除该记录？</div>',
        callback:{
          yes: function (e) {
            ajaxMethod({
                url: '/api/marketing/contact/'+item.id,
                method:'delete',
                success: function (data) {
                  getcommom()
                }
              })
          }
        },
        position:{
          width:400,
          height:200
        }
      })



    })

   })
  }
    //点击添加
    $('#addcommon_record').on('click',function(){
      var $dom=$('<div style="padding-left:15px;margin-top:10px">潜客姓名：'+name+'</div>\
        <div class="formList" style="margin-top:20px">\
          <div class="formLi">\
            <div class="formTitle formTitle">\
                <span >内容</span >\
            </div>\
            <div class="formContent">\
                <textarea rows="10" cols="70"  name="contentname" style="padding-left:15px;"></textarea>\
            </div>\
        </div></div>');
        var popUpBox=new PopUpBox({
          type:'dom',
          style:'default contentScroll',
          submitBtnType:'alert',
          titleText:'请填写信息',
          drag:true,
          show:true,
          content:$dom,
          callback:{
            yes: function (e) {
              var content=$('[name="contentname"]').val();
                $.ajax({
                  url: '/api/marketing/contact',
                  type: 'post',
                  data:{
                    clientid :id,
                    content:content
                  },
                  success:function(data){
                     window.location.reload();

                  }
                })
            }
          },
          position:{
            width:600,
            height:500
          }

        })
        //$('.submitBtnBox').css('text-align','right')
    })
 getcommom()
})
